using System.Threading.Tasks;
using ai520v.Services;
using Microsoft.AspNetCore.Mvc;

namespace ai520v.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class UserController : ControllerBase
    {
        private readonly UserService _userService;

        public UserController(UserService userService)
        {
            _userService = userService;
        }

        [HttpPost("register")]
        public async Task<IActionResult> Register([FromBody] RegisterRequest request)
        {
            var (success, message) = await _userService.RegisterAsync(request.Username, request.Password, request.Phone);

            if (success)
            {
                return Ok(new { message });
            }

            return BadRequest(new { message });
        }
    }

    public class RegisterRequest
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public string Phone { get; set; }
    }
}